package com.huishu.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huishu.commons.pojo.Result;
import com.huishu.user.mapper.UrlManageMapper;
import com.huishu.user.pojo.dto.UrlManagePageDTO;
import com.huishu.user.pojo.model.UrlManageDO;
import com.huishu.user.service.UrlManageService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author generator@ljj
 * @since 2023-06-16
 */
@Service
public class UrlManageServiceImpl extends ServiceImpl<UrlManageMapper, UrlManageDO> implements UrlManageService {

    @Override
    public Result pageList(UrlManagePageDTO urlManagePageDTO) {
        Page<UrlManageDO> page = new Page<>(urlManagePageDTO.getCurrPage(), urlManagePageDTO.getPageSize());
        if (urlManagePageDTO.getType() != 3) {
            LambdaQueryWrapper<UrlManageDO> queryWrapper = Wrappers.lambdaQuery(UrlManageDO.class)
                    .eq(urlManagePageDTO.getType() != null, UrlManageDO::getType, urlManagePageDTO.getType())
                    .like(StringUtils.isNotBlank(urlManagePageDTO.getName()), UrlManageDO::getName, urlManagePageDTO.getName())
                    .orderByAsc(UrlManageDO::getCreatedDate);
            return Result.success(this.baseMapper.selectPage(page,queryWrapper));
        }
        return Result.success(this.baseMapper.pageList(page, urlManagePageDTO));
    }
}
